﻿using System.IO;

namespace Azure.Online.Proxy {
    public class StreamUtils {

        public static void CopyStream(Stream source, Stream target, long length) {
            var buffer = new byte[4096];
            var rest = length;
            while (rest > 0) {
                var read = source.Read(buffer, 0, (int)(rest < buffer.Length ? rest : buffer.Length));
                if (read == 0) break;
                target.Write(buffer, 0, read);
                rest -= read;
            };
        }

        public static void CopyStream(Stream source, Stream target) {
            var buffer = new byte[4096];
            while (true) {
                var read = source.Read(buffer, 0, buffer.Length);
                if (read == 0) break;
                target.Write(buffer, 0, read);
            };
        }
    }
}
